﻿using Super_Management_Mayhem.Content.Spritesheet;
using Transformable_Engine_v2.Engine.Animation.ColorAnimation;
using Transformable_Engine_v2.Engine.Animation.PositionAnimation;
using Transformable_Engine_v2.Engine.Animation.Trajectory;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Super_Management_Mayhem.Screens.Menu.SelectTeams
{
    public class PlayerIcon : Container
    {
        private readonly ImageContainer _colorSelector;

        public PlayerIcon(Color color,
                          bool active)
        {
            Container imageContainer = new Container();

            imageContainer.AddChildren(new ImageContainer {
                                               Sprite = MenuSheet.GetSprite(MenuSheet.PlayerIcon.Background),
                                               Origin = TE_Rectangle.Alignment.BottomMiddle
                                           });

            _colorSelector = new ImageContainer {
                                                    Sprite = MenuSheet.GetSprite(MenuSheet.PlayerIcon.ColorSelector),
                                                    Origin = TE_Rectangle.Alignment.BottomMiddle,
                                                    Color = color
                                                };
            imageContainer.AddChildren(_colorSelector);

            if(active)
                imageContainer.AddAnimations(new PositionAnimation(new SinusTrajectory(), new TE_Vector2(0, -0.5f), 1500, true, 0));

            AddChildren(imageContainer);
        }

        public void ChangeColor(Color color,
                                int time)
        {
            _colorSelector.ClearAnimation();
            _colorSelector.AddAnimations(new ColorAnimation(new LinearEasing(), color, time, false, 0));
        }
    }
}